package com.vr.cloudpicture.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * COS 客户端配置
 *
 * @author hzh
 * @date 2025/05/07
 */
@Configuration
@ConfigurationProperties(prefix = "cos.client")
@Data
public class CosClientConfig {
    /** 主机 */
    private String host;
    /** 密钥 ID */
    private String secretId;
    /** 密钥 注意不要泄露 */
    private String secretKey;
    /** 地区 */
    private String region;
    /** 桶 */
    private String bucket;

    @Bean
    public COSClient cosClient() {
        // 初始化用户身份
        COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
        // 2 设置 bucket 的地域, COS 地域的简称请参见 https://cloud.tencent.com/document/product/436/6224
        ClientConfig clientConfig = new ClientConfig(new Region(region));
        // 3 生成 cos 客户端。
        return new COSClient(cred, clientConfig);
    }
}
